﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;

namespace Excel1316AddIn01
{
    // ZC: 下载 Download Visual Studio 2010 Tools for Office Runtime from Official Microsoft Download Center.html(https://www.microsoft.com/en-us/download/details.aspx?id=56961)
    // ZC: Visual Studio Tools for Office runtime overview - Visual Studio _ Microsoft Docs.html(https://docs.microsoft.com/en-us/visualstudio/vsto/visual-studio-tools-for-office-runtime-overview?view=vs-2019)
    // ZC:  上面这个里面说到，安装Office的时候，所需的对应版本的vstor已经和Office一起被安装了。
    // ZC:  要卸载它的话：控制面板-->程序和功能--> ... -->"Microsoft Visual Studio 2010 Tools for Office Runtime"--> 卸载。
    // ZC:  (后面的2个不知道是Office装的还是VS装的了...)SH的机子里面已有"Microsoft Visual Studio 2010 Tools for Office Runtime (x64)"和"Microsoft Visual Studio 2010 Tools for Office Runtime (x64)语言包 - 简体中文"

    public partial class ThisAddIn
    {
        Excel.Application ExcelApp;// ZC: 声明一个Excel的应用程序对象

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            ExcelApp = Globals.ThisAddIn.Application;// ZC: 获取到加载项所在的Excel应用程序
            //ExcelApp.ActiveCell.Value = "Startup";// ZC:活动单元格输入新的值
            Console.WriteLine("ThisAddIn_Startup");

            UserControl1 uc1 = new UserControl1();
            Share.Task1 = Globals.ThisAddIn.CustomTaskPanes.Add(uc1, "工作表导航");
            Share.Task1.Visible = true;

            Share.Task1.VisibleChanged += new EventHandler(Task1_VisibleChanged);
            Share.Task1.DockPositionChanged += new EventHandler(Task1_DockPositionChanged);
        }

        void Task1_VisibleChanged(object sender, System.EventArgs e)
        {
            //RibbonC7 ribbon1 = Globals.Ribbons.GetRibbon<RibbonC7>();// 获得 功能区可视化设计器中的Ribbon
            //ribbon1.toggleButton1.Checked = Share.Task1.Visible;
        }

        void Task1_DockPositionChanged(object sender, System.EventArgs e)
        {
            //RibbonC7 ribbon1 = Globals.Ribbons.GetRibbon<RibbonC7>();// 获得 功能区可视化设计器中的Ribbon
            //Globals.ThisAddIn.Application.StatusBar = Share.Task1.DockPosition.ToString();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            Console.WriteLine("ThisAddIn_Shutdown");
        }

        #region VSTO 生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要修改
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InternalStartup()
        {
            Console.WriteLine("InternalStartup(...) - 1");
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

            Console.WriteLine("InternalStartup(...) - 2");
        }

        #endregion
    }
}
